#include<cstring>
#include<cstdio>
const int maxn=120010;
const int P=6000;
const int INF=0x3f3f3f3f;
int f[2][maxn],a[1001],b[1001],n;
int min(int x,int y){return x<y?x:y;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i],&b[i]);
	memset(f,0x3f3f3f3f,sizeof(f));
	f[1][a[1]-b[1]+P]=0;f[1][b[1]-a[1]+P]=1;
	for(int i=2;i<=n;i++)
		for(int j=P-6*n;j<=P+6*n;j++)
		{
			f[i%2][j]=INF;
			if(j-(a[i]-b[i])>=P-6*n&&j-(a[i]-b[i])<=P+6*n)
				if(f[(i-1)%2][j-(a[i]-b[i])]!=INF)
				f[i%2][j]=f[(i-1)%2][j-(a[i]-b[i])];
			if(j-(a[i]-b[i])>=P-6*n&&j-(a[i]-b[i])<=P+6*n)
				if(f[(i-1)%2][j+(a[i]-b[i])]!=INF)
				f[i%2][j]=min(f[i%2][j],f[(i-1)%2][j+(a[i]-b[i])]+1);
		}
	int ans=INF;
	for(int i=0;i<=6*n;i++)
	{
		if(f[n%2][i+P]!=INF){ans=f[n%2][i+P];}
		if(f[n%2][P-i]!=INF){ans=min(ans,f[n%2][P-i]);}
		if(ans<INF)break;
	}
	printf("%d\n",ans);
	return 0;
}


